package common.utils.entity;

import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
/**
 * <p>分页插件参数</p>
 *@author zwy
 *@date 2025/3/9 18:03
*/

public class RequestBaseTableEntity {
    @ApiModelProperty("当前记录起始索引(默认1)")
    private Integer page = 1;

    @ApiModelProperty(value = "用于sql查询时使用", hidden = true)
    private Integer mypage = 0;

    @ApiModelProperty("每页显示记录数(默认10 若为-1则查询全部数据)")
    private Integer limit = 10;

    //@Pattern(regexp = "^(\\s*|asc|desc|ASC|DESC)$", message = "序号排序格式错误")
    @ApiModelProperty("序号排序(默认为空 asc升序 desc降序)")
    private String order = "asc";

    public Integer getMypage() {
        return mypage;
    }

    public void setMypage(Integer myPage) {
        if (page == null) {
            this.page = 0;
            this.mypage = 0;
        }
        this.mypage = myPage;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        // 前端传值page从1开始 ,但sql是从0开始
        if (page == null) {
            this.page = 0;
            this.mypage = 0;
        } else {
            if (page >= 1) {
                page = page - 1;
            } else {
                page = 0;
            }
            this.page = page;
            this.mypage = page * (limit == null ? 10 : limit);
        }
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit == null ? 10 : limit;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = StringUtils.isBlank(order) ? "asc" : order;
    }
}
